package com.ruoyi.system.service.impl;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.Employee;
import com.ruoyi.system.mapper.EmployeeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.TrainGradeMapper;
import com.ruoyi.system.domain.TrainGrade;
import com.ruoyi.system.service.ITrainGradeService;
import com.ruoyi.common.core.text.Convert;

/**
 * 培训考核Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-05-12
 */
@Service
public class TrainGradeServiceImpl implements ITrainGradeService 
{
    @Autowired
    private TrainGradeMapper trainGradeMapper;

    @Autowired
    private EmployeeMapper employeeMapper;

    /**
     * 查询培训考核
     * 
     * @param tgId 培训考核主键
     * @return 培训考核
     */
    @Override
    public TrainGrade selectTrainGradeByTgId(Long tgId)
    {
        return trainGradeMapper.selectTrainGradeByTgId(tgId);
    }

    /**
     * 查询培训考核列表
     * 
     * @param trainGrade 培训考核
     * @return 培训考核
     */
    @Override
    @DataScope(deptAlias = "e")
    public List<TrainGrade> selectTrainGradeList(TrainGrade trainGrade)
    {
        return trainGradeMapper.selectTrainGradeList(trainGrade);
    }

    /**
     * 新增培训考核
     * 
     * @param trainGrade 培训考核
     * @return 结果
     */
    @Override
    public int insertTrainGrade(TrainGrade trainGrade)
    {
        trainGrade.setCreateTime(DateUtils.getNowDate());
        return trainGradeMapper.insertTrainGrade(trainGrade);
    }

    /**
     * 修改培训考核
     * 
     * @param trainGrade 培训考核
     * @return 结果
     */
    @Override
    public int updateTrainGrade(TrainGrade trainGrade)
    {
        trainGrade.setUpdateTime(DateUtils.getNowDate());
        return trainGradeMapper.updateTrainGrade(trainGrade);
    }

    /**
     * 批量删除培训考核
     * 
     * @param tgIds 需要删除的培训考核主键
     * @return 结果
     */
    @Override
    public int deleteTrainGradeByTgIds(String tgIds)
    {
        return trainGradeMapper.deleteTrainGradeByTgIds(Convert.toStrArray(tgIds));
    }

    /**
     * 删除培训考核信息
     * 
     * @param tgId 培训考核主键
     * @return 结果
     */
    @Override
    public int deleteTrainGradeByTgId(Long tgId)
    {
        return trainGradeMapper.deleteTrainGradeByTgId(tgId);
    }

    @Override
    public int toEmployee(Long employeeId) {
        Employee employee = employeeMapper.selectEmployeeByEmployeeId(employeeId);
        String oldName = employee.getEmployeeName();
        int index=oldName.indexOf("(实习)");
        String newName=oldName.substring(0,index);
        System.out.println(newName);
        employee.setEmployeeName(newName);
        employee.setIsTrainee("否");
        employee.setUpdateTime(new Date());
        return employeeMapper.updateEmployee(employee);
//        return trainGradeMapper.deleteByEmployeeId(employeeId);
    }


}
